﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using QUANLIHOCSINH.BussinessObject;
using QUANLIHOCSINH.BussinessLogic;
using QUANLIHOCSINH.DataAccess;
namespace QUANLIHOCSINH
{
    public partial class FrmMain : Form
    {
        FrmDangNhap frmdangnhap;
        public FrmMain()
        {
            InitializeComponent();
        }

        private void giúpĐỡToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        private void PhanQuyen(int MaNhom)
        {
            switch (MaNhom)
            {
                case 1:
                    MenuDangNhap.Enabled = false;
                        MenuDangXuat.Enabled = true;
                        MenuThayDoiMatKhau.Enabled = true;
                        //MenuDoiThongTin.Enabled = logger;
                        MenuNghiepVu.Enabled = true;
                        MenuThongKe.Enabled = true;
                        MenuDangNhap.Visible = true;
                        MenuDangXuat.Visible = true;
                        MenuQuanLiQuiDinh.Visible = true;
                        MenuQuanLiNamHoc.Visible = true;
                        MenuQuanLiMonHoc.Visible = true;
                        MenuQuanLiNguoiDung.Visible = true;
                        MenuQuanLiLopHoc.Visible = true;
                        MenuQuanLiHieuTruong.Visible = true;
                        MenuPhanLop.Visible = true;
                        MenuQuanLiDiem.Visible = true;
                    break;
                case 2:
                        MenuDangNhap.Enabled = false;
                        MenuDangXuat.Enabled = true;
                        MenuThayDoiMatKhau.Enabled = true;
                        //MenuDoiThongTin.Enabled = logger;
                        MenuNghiepVu.Enabled = true;
                        MenuThongKe.Enabled = true;
                        MenuDangNhap.Visible = true;
                        MenuDangXuat.Visible = true;
                        MenuQuanLiQuiDinh.Visible = true;
                        MenuQuanLiNamHoc.Visible = true;
                        MenuQuanLiMonHoc.Visible = true;
                        MenuQuanLiNguoiDung.Visible = true;
                        MenuQuanLiLopHoc.Visible = true;
                        MenuQuanLiHieuTruong.Visible = false;
                        MenuPhanLop.Visible = true;
                        MenuQuanLiDiem.Visible = true;
                    
                    break;
                case 3:
                        MenuDangNhap.Enabled = false;
                        MenuDangXuat.Enabled = true;
                        MenuThayDoiMatKhau.Enabled = true;
                        //MenuDoiThongTin.Enabled = logger;
                        MenuNghiepVu.Enabled = true;
                        MenuThongKe.Enabled = true;
                        MenuDangNhap.Visible = true;
                        MenuDangXuat.Visible = true;
                        MenuQuanLiQuiDinh.Visible = true;
                        MenuQuanLiNamHoc.Visible = true;
                        MenuQuanLiMonHoc.Visible = true;
                        MenuQuanLiNguoiDung.Visible = true;
                        MenuQuanLiLopHoc.Visible = true;
                        MenuQuanLiHieuTruong.Visible = false;
                        MenuPhanLop.Visible = true;
                        MenuQuanLiDiem.Visible = false;
                    break;
                case 4:
                        MenuDangNhap.Enabled = false;
                        MenuDangXuat.Enabled = true;
                        MenuThayDoiMatKhau.Enabled = true;
                        //MenuDoiThongTin.Enabled = logger;
                        MenuNghiepVu.Enabled = true;
                        MenuThongKe.Enabled = true;
                        MenuDangNhap.Visible = true;
                        MenuDangXuat.Visible = true;
                        MenuQuanLiQuiDinh.Visible = false;
                        MenuQuanLiNamHoc.Visible = false;
                        MenuQuanLiMonHoc.Visible = false;
                        MenuQuanLiNguoiDung.Visible = false;
                        MenuQuanLiLopHoc.Visible = false;
                        MenuQuanLiHieuTruong.Visible = false;
                        MenuPhanLop.Visible = false;
                        MenuQuanLiDiem.Visible = true;
                        MenuQuanLiHieuTruong.Visible = false;
                        MenuQuanLiHocSinh.Visible = false;
                    
                    break;
                case 0:
                    DisplayMenu(false);
                    break;
            }
        }
        private void DisplayMenu(bool logger)
        {
            MenuDangNhap.Enabled = !logger;
            MenuDangXuat.Enabled = logger;
            MenuThayDoiMatKhau.Enabled = logger;
            //MenuDoiThongTin.Enabled = logger;
            MenuNghiepVu.Enabled = logger;
            MenuThongKe.Enabled = logger;
            MenuDangNhap.Visible = !logger;
            MenuDangXuat.Visible = logger;
            

        }
        private void MenuDangNhap_Click(object sender, EventArgs e)
        {
        Login:
            if (frmdangnhap == null || frmdangnhap.IsDisposed)
                frmdangnhap = new FrmDangNhap();

            if (frmdangnhap.ShowDialog() == DialogResult.Yes)
            {

                string tendangnhap = frmdangnhap.txttendangnhap.Text;
                string matkhau = frmdangnhap.txtmatkhau.Text;
                if (tendangnhap.Equals(""))
                {
                    frmdangnhap.lbtrangthai.Text = "Tài Khoản Không được bỏ trống";
                    goto Login;
                }
                if (matkhau.Equals(""))
                {
                    frmdangnhap.lbtrangthai.Text = "Mật Khẩu Không được bỏ trống";
                    goto Login;
                }
                NGUOIDUNGBUS nguoidung = new NGUOIDUNGBUS();
                Utility.user = nguoidung.LayThongTinNguoiDung(tendangnhap, matkhau);
                if (nguoidung.checklogin(tendangnhap, matkhau) == true)
                {
                    PhanQuyen(int.Parse(Utility.user.MaNhom));
                    toolStripStatusLabel1.Text = Utility.user.TenNguoiDung + " : " + Utility.user.TenNhom;
                }
                else
                {
                    frmdangnhap.lbtrangthai.Text = "Tài Khoản Hoặc Mật Khẩu Sai";
                    goto Login;
                }
            }
        }
       
        private void MenuThayDoiMatKhau_Click(object sender, EventArgs e)
        {
            FrmThayDoiMatKhau frmdoimatkhau = new FrmThayDoiMatKhau();
            frmdoimatkhau.Show();
        }

        private void MenuQuanLiQuiDinh_Click(object sender, EventArgs e)
        {
            FrmThayDoiQuiDinh frmquidinh = new FrmThayDoiQuiDinh();
            frmquidinh.Show();
        }

        private void MenuQuanLiNamHoc_Click(object sender, EventArgs e)
        {
            FrmQuanLiNamHoc frmnamhoc = new FrmQuanLiNamHoc();
            frmnamhoc.Show();
        }

        private void MenuQuanLiMonHoc_Click(object sender, EventArgs e)
        {
            FrmQuanLiMonHoc frmmonhoc = new FrmQuanLiMonHoc();
            frmmonhoc.Show();
        }

        private void MenuQuanLiLopHoc_Click(object sender, EventArgs e)
        {
            FrmQuanLiLopHoc frmlophoc = new FrmQuanLiLopHoc();
            frmlophoc.Show();
        }

        private void MenuQuanLiHocSinh_Click(object sender, EventArgs e)
        {
            FrmQuanLiHocSinh frmhocsinh = new FrmQuanLiHocSinh();
            frmhocsinh.Show();
        }

        private void MenuPhanLop_Click(object sender, EventArgs e)
        {
            FrmPhanLop frmphanlop = new FrmPhanLop();
            frmphanlop.Show();
        }

        private void MenuQuanLiDiem_Click(object sender, EventArgs e)
        {
            FrmQuanLiDiem frmdiem = new FrmQuanLiDiem();
            frmdiem.Show();
        }

        private void MenuQuanLiNguoiDung_Click(object sender, EventArgs e)
        {
            FrmQuanLiNguoiDung frmnguoidung = new FrmQuanLiNguoiDung();
            frmnguoidung.Show();
        }

        private void MenuTraCuu_Click(object sender, EventArgs e)
        {
            FrmTraCuuDiem frmtracuudiem = new FrmTraCuuDiem();
            frmtracuudiem.Show();
        }

        private void MenuThongKeHocKy_Click(object sender, EventArgs e)
        {
            FrmThongKeHocKy frmhocky = new FrmThongKeHocKy();
            frmhocky.Show();
        }

        private void MenuThongKeCaNam_Click(object sender, EventArgs e)
        {
            FrmThongKeNamHoc frmcanam = new FrmThongKeNamHoc();
            frmcanam.Show();
        }

        private void MenuTroGiup_Click(object sender, EventArgs e)
        {
            FrmThuNGhiem thunghiem = new FrmThuNGhiem();
            thunghiem.Show();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            QUIDINHBUS qd = new QUIDINHBUS();
            Utility.quidinh = qd.LayDanhSachQuiDinh();

            MenuDangNhap.Enabled = true;
            MenuDangXuat.Enabled = false;
            MenuThayDoiMatKhau.Enabled = false;
            //MenuDoiThongTin.Enabled = logger;
            MenuNghiepVu.Enabled = false;
            MenuThongKe.Enabled = false;
            MenuDangNhap.Visible = true;
            MenuDangXuat.Visible = false;
            MenuQuanLiQuiDinh.Visible = false;
            MenuQuanLiNamHoc.Visible = false;
            MenuQuanLiMonHoc.Visible = false;
            MenuQuanLiNguoiDung.Visible = false;
            MenuQuanLiLopHoc.Visible = false;
            MenuQuanLiHieuTruong.Visible = false;
            MenuPhanLop.Visible = false;
            MenuQuanLiDiem.Visible = false;
            //frmdangnhap.txttendangnhap.Clear();
            //frmdangnhap.txtmatkhau.Text = "";
           
           
           
        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void MenuDangXuat_Click(object sender, EventArgs e)
        {
            DisplayMenu(false);
           
            toolStripStatusLabel1.Text = "Chưa Đăng Nhập";
            Utility.user.MaNguoiDung = "";
            Utility.user.MatKhau = "";
            Utility.user.MaNhom = "";
            Utility.user.TenNguoiDung = "";
            Utility.user.GioiTinh = "";


            MenuDangNhap.Enabled = true;
            MenuDangXuat.Enabled = false;
            MenuThayDoiMatKhau.Enabled = false;
            //MenuDoiThongTin.Enabled = logger;
            MenuNghiepVu.Enabled = false;
            MenuThongKe.Enabled = false;
            MenuDangNhap.Visible = true;
            MenuDangXuat.Visible = false;
            MenuQuanLiQuiDinh.Visible = false;
            MenuQuanLiNamHoc.Visible = false;
            MenuQuanLiMonHoc.Visible = false;
            MenuQuanLiNguoiDung.Visible = false;
            MenuQuanLiLopHoc.Visible = false;
            MenuQuanLiHieuTruong.Visible = false;
            MenuPhanLop.Visible = false;
            MenuQuanLiDiem.Visible = false;

        }

      
    }
}
